namespace ACRSAP.Administration.Projects
{
    using ASPNET.StarterKit.IssueTracker.UserInterfaceLayer;
    using Microsoft.VisualBasic.CompilerServices;
    using System;
    using System.Collections;
    using System.Diagnostics;
    using System.Runtime.CompilerServices;
    using System.Web.UI;
    using System.Web.UI.WebControls;

    public class AddProject : Page
    {
        [AccessedThroughProperty("btnBack")]
        private Button _btnBack;
        [AccessedThroughProperty("btnCancel")]
        private Button _btnCancel;
        [AccessedThroughProperty("btnNext")]
        private Button _btnNext;
        [AccessedThroughProperty("lblStepNumber")]
        private Literal _lblStepNumber;
        [AccessedThroughProperty("plhWizardStep")]
        private PlaceHolder _plhWizardStep;
        private Control ctlWizardStep;
        private object designerPlaceholderDeclaration;
        private ArrayList WizardSteps;

        public AddProject()
        {
            base.Init += new EventHandler(this.Page_Init);
            base.Load += new EventHandler(this.Page_Load);
            base.PreRender += new EventHandler(this.Page_PreRender);
            this.WizardSteps = new ArrayList();
        }

        public void BackStep(object s, EventArgs e)
        {
            this.StepIndex--;
            this.LoadWizardStep();
        }

        public void Cancel(object s, EventArgs e)
        {
            this.Response.Redirect("ProjectList.aspx");
        }

        [DebuggerStepThrough]
        private void InitializeComponent()
        {
        }

        public void LoadWizardStep()
        {
            this.ctlWizardStep = this.Page.LoadControl(StringType.FromObject(this.WizardSteps[this.StepIndex]));
            this.ctlWizardStep.ID = "ctlWizardStep";
            ((IEditProjectControl) this.ctlWizardStep).ProjectId = this.ProjectId;
            this.plhWizardStep.Controls.Clear();
            this.plhWizardStep.Controls.Add(this.ctlWizardStep);
            ((IEditProjectControl) this.ctlWizardStep).Initialize();
            this.lblStepNumber.Text = string.Format("Step {0} of {1}", this.StepIndex + 1, this.WizardSteps.Count);
        }

        public void NextStep(object s, EventArgs e)
        {
            if (((IEditProjectControl) this.ctlWizardStep).Update())
            {
                this.ProjectId = ((IEditProjectControl) this.ctlWizardStep).ProjectId;
                this.StepIndex++;
                if (this.StepIndex == this.WizardSteps.Count)
                {
                    this.Response.Redirect("ProjectList.aspx");
                }
                else
                {
                    this.LoadWizardStep();
                }
            }
        }

        private void Page_Init(object sender, EventArgs e)
        {
            this.InitializeComponent();
        }

        private void Page_Load(object sender, EventArgs e)
        {
            if (this.Request.Cookies["skipprojectintro"] == null)
            {
                this.WizardSteps.Add("UserControls/NewProjectIntro.ascx");
            }
            this.WizardSteps.Add("UserControls/ProjectDescription.ascx");
            this.WizardSteps.Add("UserControls/ProjectCategories.ascx");
            this.WizardSteps.Add("UserControls/ProjectStatus.ascx");
            this.WizardSteps.Add("UserControls/ProjectPriorities.ascx");
            this.WizardSteps.Add("UserControls/ProjectCustomFields.ascx");
            this.WizardSteps.Add("UserControls/ProjectMembers.ascx");
            this.WizardSteps.Add("UserControls/NewProjectSummary.ascx");
            this.LoadWizardStep();
        }

        private void Page_PreRender(object sender, EventArgs e)
        {
            if (this.StepIndex == 0)
            {
                this.btnBack.Visible = false;
            }
            else
            {
                this.btnBack.Visible = true;
            }
            if (this.StepIndex == (this.WizardSteps.Count - 1))
            {
                this.btnNext.Text = "Finish";
            }
            else
            {
                this.btnNext.Text = "Next";
            }
        }

        protected virtual Button btnBack
        {
            get
            {
                return this._btnBack;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                if (this._btnBack != null)
                {
                    this._btnBack.Click -= new EventHandler(this.BackStep);
                }
                this._btnBack = value;
                if (this._btnBack != null)
                {
                    this._btnBack.Click += new EventHandler(this.BackStep);
                }
            }
        }

        protected virtual Button btnCancel
        {
            get
            {
                return this._btnCancel;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                if (this._btnCancel != null)
                {
                    this._btnCancel.Click -= new EventHandler(this.Cancel);
                }
                this._btnCancel = value;
                if (this._btnCancel != null)
                {
                    this._btnCancel.Click += new EventHandler(this.Cancel);
                }
            }
        }

        protected virtual Button btnNext
        {
            get
            {
                return this._btnNext;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                if (this._btnNext != null)
                {
                    this._btnNext.Click -= new EventHandler(this.NextStep);
                }
                this._btnNext = value;
                if (this._btnNext != null)
                {
                    this._btnNext.Click += new EventHandler(this.NextStep);
                }
            }
        }

        protected virtual Literal lblStepNumber
        {
            get
            {
                return this._lblStepNumber;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                if (this._lblStepNumber != null)
                {
                }
                this._lblStepNumber = value;
                if (this._lblStepNumber != null)
                {
                }
            }
        }

        protected virtual PlaceHolder plhWizardStep
        {
            get
            {
                return this._plhWizardStep;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                if (this._plhWizardStep != null)
                {
                }
                this._plhWizardStep = value;
                if (this._plhWizardStep != null)
                {
                }
            }
        }

        public int ProjectId
        {
            get
            {
                if (this.ViewState["ProjectId"] == null)
                {
                    return -1;
                }
                return IntegerType.FromObject(this.ViewState["ProjectId"]);
            }
            set
            {
                this.ViewState["ProjectId"] = value;
            }
        }

        public int StepIndex
        {
            get
            {
                if (this.ViewState["StepIndex"] == null)
                {
                    return 0;
                }
                return IntegerType.FromObject(this.ViewState["StepIndex"]);
            }
            set
            {
                this.ViewState["StepIndex"] = value;
            }
        }
    }
}

